<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改机构信息')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-org-edit" th:object="${businessOrg}">
            <input name="orgId" th:field="*{orgId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">机构名称：</label>
                <div class="col-sm-8">
                    <input name="orgName" th:field="*{orgName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">机构英文名称：</label>
                <div class="col-sm-8">
                    <input name="orgEnglishName" th:field="*{orgEnglishName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">机构Logo：</label>
                <div class="col-sm-8">
                    <div class="fileinput fileinput-new" data-provides="fileinput">
                        <div class="fileinput-new thumbnail" style="width: 140px; height: 140px;">
                            <img th:src="*{orgLogo}"/>
                        </div>
                        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                        <div>
                            <span class="btn btn-white btn-file">
                                    <span class="fileinput-new">选择图片</span>
                                    <span class="fileinput-exists">更改</span>
                                    <input id="orgLogo" name="orgLogo" type="file">
                                </span>
                            <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">机构标语：</label>
                <div class="col-sm-8">
                    <input name="orgSologan" th:field="*{orgSologan}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">机构图片：</label>
                <div class="col-sm-8">
                    <div class="fileinput fileinput-new" data-provides="fileinput">
                        <div class="fileinput-new thumbnail" style="width: 140px; height: 140px;">
                            <img th:src="*{orgImg}"/>
                        </div>
                        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                        <div>
                            <span class="btn btn-white btn-file">
                                    <span class="fileinput-new">选择图片</span>
                                    <span class="fileinput-exists">更改</span>
                                    <input id="orgImg" name="orgImg" type="file">
                                </span>
                            <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">机构简介：</label>
                <div class="col-sm-8">
                    <textarea name="orgSummary" th:field="*{orgSummary}" class="form-control"  rows="3" maxlength="500"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">机构管理员账号：</label>
                <div class="col-sm-8">
                    <input id="orgAccount" name="orgAccount" th:field="*{orgAccount}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">机构管理员密码：</label>
                <div class="col-sm-8">
                    <input id="orgPwd" name="orgPwd" th:field="*{orgPwd}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/org";
        $("#form-org-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            var formData = new FormData();

            formData.append('orgId', $("#orgId").val());
            formData.append('orgName', $("#orgName").val());
            formData.append('orgEnglishName', $("#orgEnglishName").val());
            formData.append('orgSummary', $("#orgSummary").val());
            formData.append('orgImgFile', $("#orgImg")[0].files[0]);
            formData.append('orgLogoFile', $("#orgLogo")[0].files[0]);
            formData.append('orgSologan', $("#orgSologan").val());
            formData.append('orgAccount', $("#orgAccount").val());
            formData.append('orgPwd', $("#orgPwd").val());
            $.ajax({
                url: prefix + "/edit",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
            // if ($.validate.form()) {
            //     $.operate.save(prefix + "/edit", $('#form-org-edit').serialize());
            // }
        }
    </script>
</body>
</html>